package refactortips.editors.refactorings;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;

public class EncapsulateFieldEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public EncapsulateFieldEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmRefactoring = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmRefactoring);
		frmRefactoring.setText("Encapsulate Field");
		frmRefactoring.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmRefactoring.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Link linkMoveMethod = new Link(composite_3, SWT.NONE);
		linkMoveMethod.setBounds(227, 475, 97, 21);
		linkMoveMethod.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		formToolkit.adapt(linkMoveMethod, true, true);
		linkMoveMethod.setText("<a>Move Method</a>");
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tUm dos principais princ\u00EDpios da orienta\u00E7\u00E3o a objeto \u00E9 o encapsulamento, ou ocultamento de dados. Isso diz que voc\u00EA nunca deve tornar os seus dados p\u00FAblicos. Quando voc\u00EA faz com que um dado seja p\u00FAblico, outros objetos pode alterar e acessar os valores dos dados sem que o objeto a que elas pertencem saiba disso. Isso separa os dados do comportamento.");
		styledText.setBounds(29, 202, 803, 98);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		Label label = new Label(composite_3, SWT.NONE);
		label.setText("Motiva\u00E7\u00E3o");
		label.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label.setBounds(10, 155, 98, 25);
		formToolkit.adapt(label, true, true);
		
		Label label_1 = new Label(composite_3, SWT.NONE);
		label_1.setText("Atalho");
		label_1.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label_1.setBounds(10, 567, 78, 42);
		formToolkit.adapt(label_1, true, true);
		
		Label lblAbraUmaClasse = new Label(composite_3, SWT.NONE);
		lblAbraUmaClasse.setText("Abra uma classe e pressione");
		lblAbraUmaClasse.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		lblAbraUmaClasse.setAlignment(SWT.CENTER);
		lblAbraUmaClasse.setBounds(94, 570, 234, 21);
		formToolkit.adapt(lblAbraUmaClasse, true, true);
		
		Label lblAltShift = new Label(composite_3, SWT.NONE);
		lblAltShift.setText("Alt + Shift + S -> R");
		lblAltShift.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.BOLD));
		lblAltShift.setAlignment(SWT.CENTER);
		lblAltShift.setBounds(344, 570, 140, 21);
		formToolkit.adapt(lblAltShift, true, true);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tIsso \u00E9 visto como algo ruim porque reduz a modularidade do programa. Quando os dados e o comportamento que o usa est\u00E3o agrupados \u00E9 mais f\u00E1cil alterar o c\u00F3digo, porque o c\u00F3digo alterado est\u00E1 em um lugar ao inv\u00E9s de espalhado por todo o programa.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(29, 306, 803, 80);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tEncapsulate Field inicia o processo escondendo os dados e adicionando assessores. Mas isso \u00E9 apenas o primeiro passo. Uma classe com apenas assessores \u00E9 uma classe est\u00FApida porque isso n\u00E3o tira proveito das oportunidades de objetos, e desperdi\u00E7ar um objeto \u00E9 algo terr\u00EDvel. Depois de eu ter feito Encapsulate Field eu procuro por m\u00E9todos que usam os novos m\u00E9todos para ver se eles gostam de fazer as malas e mudar-se para o novo objeto com um r\u00E1pido \t\t\t\t\t\t\t.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(29, 392, 803, 133);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		Label lblExisteUmCampo = new Label(composite_3, SWT.NONE);
		lblExisteUmCampo.setText("Existe um campo p\u00FAblico.\r\nTorne-o privado e forne\u00E7a acessores.");
		lblExisteUmCampo.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		lblExisteUmCampo.setAlignment(SWT.CENTER);
		lblExisteUmCampo.setBounds(188, 67, 496, 42);
		formToolkit.adapt(lblExisteUmCampo, true, true);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setImage(ResourceManager.getPluginImage("RefactorTips", "images/refactor/encapsulateField/encapsulateFieldSample1.1.png"));
		label_2.setBounds(10, 213, 444, 178);
		formToolkit.adapt(label_2, true, true);
		
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setImage(ResourceManager.getPluginImage("RefactorTips", "images/rightPointer.png"));
		label_3.setBounds(475, 279, 66, 36);
		formToolkit.adapt(label_3, true, true);
		
		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setImage(ResourceManager.getPluginImage("RefactorTips", "images/refactor/encapsulateField/encapsulateFieldSample1.2.png"));
		label_4.setBounds(563, 46, 444, 530);
		formToolkit.adapt(label_4, true, true);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("www.youtube.com/embed/WcF_eE_TX64");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
